#include "EthercatSlave.h"


ECatDrv::EthercatSlave::EthercatSlave(unsigned int eep_man, unsigned int eep_id, const std::string &slave_name, int slave_addr,
                                      ECatDrv::slaveType s_type)
    :s_eep_man(eep_man)
    ,s_eep_id(eep_id)
    ,slave_name(slave_name)
    ,slave_addr(slave_addr)
    ,slave_type(s_type)
{}

int ECatDrv::EthercatSlave::pdoConfigWrapper(uint16 slave_addr)
{
    auto it = slaveRegistry.find(slave_addr);
    if (it != slaveRegistry.end())
    {
        return it->second->configurePDO();
    }
    return 0;
}

void ECatDrv::EthercatSlave::registerSlave(uint16 slaveAddr, std::shared_ptr<ECatDrv::EthercatSlave> slave)
{
    slaveRegistry[slaveAddr] = slave;
    ec_slave[slaveAddr].PO2SOconfig = &EthercatSlave::pdoConfigWrapper;
}



std::map<uint16, std::shared_ptr<ECatDrv::EthercatSlave>> ECatDrv::EthercatSlave::slaveRegistry;
